package org.example.springbootdemo;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/header")
@RestController
public class Header {
    @RequestMapping("/getheader")
    public String getheader(HttpServletRequest request){
        String userAgent = request.getHeader("User-Agent");
        return "从header中获取UserAgent"+userAgent;
    }
    @RequestMapping("/getheader2")
    public String getheader2(@RequestHeader ("User-Agent") String userAgent){
        return "从header中获取UserAgent"+userAgent;
    }

}
